<?php
##############################################
#
#   扫码日志
# @ Time : 2017-1-8 - 下午9:20:27
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################


namespace Admin\Model;

class SweepLogModel extends AdminBaseModel{
	/*扫码日志表  */
	protected $tableName = 'sweep_log';	
	
	public function __construct($tableName=''){
		//初始化数据库对象
		if(!empty($tableName)){
			$this -> tableName = $tableName;
		}	
		parent::__construct($this -> tableName);
	}
	
	/**
	 * 获取记录
	 */
	public function getLog($activity_name, $order_sn, $phone_number, $sweep_user, $start_time, $end_time){
	 	if($activity_name){
			$map['activity_name'] = array('like','%'.$activity_name.'%');
		}
		if($order_sn){
			$map['order_sn'] = array('like','%'.$order_sn.'%');
		} 
		if($phone_number){
		    $map['phone_number'] = array('like','%'.$phone_number.'%');
		}
		if($sweep_user){
		    $map['sweep_user'] = $sweep_user;
		}
		if($start_time && $end_time){
		    $map['add_time'] = array(array('egt', $start_time),array('elt', $end_time)) ;
		}
	    $count = $this -> where($map)->count();// 查询满足要求的总记录数
	    $Page = new \Think\Page($count, C('listRows'));
	    $show = $Page->show();
	    $result = $this->where($map)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		return array($result, $show);
	}
	
	/**
	 * 获取一个订单
	 */
	public function getOrderFind($id){
	    return $this->where("id = $id")->find();
	}
	
	/**
	 * 修改订单
	 */
	public function editOrder($id, $data){
	    return $this->where("id = $id")->save($data);
	    
	}
	
	/**
	* 删除日志
	*/
	public function deleteLog($id){
		return $this->where("id = $id")->delete();
	}
    
	/**
	 * 全选删除订单
	 */
	public function deleteAllOrder($idArr) {
	    foreach ($idArr['order_id'] as $k => $v){
	        $this->where("id = $v")->delete();
	    }
	    return true;
	}
	
    /**
      * description
      * @date 2017年8月8日 - 下午3:37:45
      * @author JiangYongWei
     */
	public function getOrderCount($today){
	    $count['all_order'] = $this->count();
	    $count['new_order'] = $this->where("add_time > $today")->count();
	    return $count;
	}
	
	/**
	 * 获取订单
	 */
	public function getSignup($activity_id, $order_sn, $name, $mobile, $is_selected){
	    if($order_sn){
	        $map['order_sn'] = array('like','%'.$order_sn.'%');
	    }
	    if($name){
	        $map['name'] = array('like','%'.$name.'%');
	    }
	    if($mobile){
	        $map['mobile'] = array('like','%'.$mobile.'%');
	    }
	    if($is_selected){
	        $map['is_selected'] = $is_selected;
	    }
	    $map['activity_id'] = $activity_id;
	    $map['payment_status'] = 2;
	    $map['order_status'] = 2;
	    $count = $this->where($map)->count();// 查询满足要求的总记录数
	    $Page = new \Think\Page($count, C('listRows'));
	    $show = $Page->show();
	    $result = $this->field('id, order_sn, user_id, name, mobile, number, pay_time, payment_status, order_status, is_selected, add_time')
	                   ->where($map)->order('id desc')
	                   ->limit($Page->firstRow.','.$Page->listRows)->select();
	    return array($result, $show);
	}
	
}